import React from 'react'
import ReactDOM from 'react-dom'
import { createStore,applyMiddleware,combineReducers   } from 'redux'
import { Provider,connect } from 'react-redux'
import createSagaMiddleware from 'redux-saga'

function counter(state = 0, action) {
    switch (action.type) {
        case 'USER_FETCH_REQUESTED':
            return action.payload
        default:
            return state
    }
}
const sagaMiddleware = createSagaMiddleware()
const store = createStore(
    counter,
    applyMiddleware(sagaMiddleware)
)
import saga from "./saga"
sagaMiddleware.run(saga)

store.subscribe(() =>
    console.log(store.getState())
)

store.dispatch({ type: 'USER_FETCH_REQUESTED' })
store.dispatch({ type: 'INCREMENT' })
store.dispatch({ type: 'DECREMENT' })

const App=()=><div>app</div>

const Test=connect()(App)

ReactDOM.render(
    <Provider store={store}><h1><Test/></h1></Provider>,
    document.getElementById('root')
)


